package com.example.concurrentprogramming8016.thread;

/**
 * @author liyanhao
 * @Date 2023-01-03 16:25
 */
public class StopThread implements Runnable {

    @Override
    public void run() {
        int count = 0;
        while (!Thread.currentThread().isInterrupted() && count < 1000) {
            System.out.println("count = " + count++);

        }
        System.out.println("线程暂停：stop thread");
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new StopThread());
        thread.start();
        Thread.sleep(5000);
        System.out.println("调用线程暂停方法");
        thread.interrupt();
    }
}
